﻿using NetSurveillance.WebApp.DataServices.Models;
using ServiceStack.OrmLite;

namespace NetSurveillance.WebApp.DataServices.Implementations
{
    public class RemoteServerService : BaseService<RemoteServer>
    {
        public RemoteServerService(string connStr, IOrmLiteDialectProvider provider = null)
            : base(connStr, provider)
        {
        }

        /// <summary>
        /// 获取最后一条更新的远程服务器信息
        /// </summary>
        /// <returns>远程服务器信息</returns>
        public RemoteServer GetLastRemoteSvr()
        {
            RemoteServer rmSvr;
            using (var db = DbFactory.OpenDbConnection())
            {
                const string searchSql =
                    @"select * from ""RemoteServers"" as RS 
                        order by RS.""Id"" desc limit 1";
                rmSvr = db.QuerySingle<RemoteServer>(searchSql);
            }
            return rmSvr;
        }
    }
}